import { Material } from './../../../../@core/data/material';
import { ActivatedRoute, Router } from '@angular/router';
import { JobOrderService } from './../../../../@core/services/jobOrder/job-order.service';
import { Component } from '@angular/core';

@Component({
  selector: 'app-view-product-job',
  templateUrl: './view-product-job.component.html',
  styleUrls: ['./view-product-job.component.scss']
})
export class ViewProductJobComponent {
  constructor(private JobOrderService:JobOrderService,private ActivatedRoute:ActivatedRoute,private Router:Router) { }
  jobOrderId:number=null;
  isCollapsed = {
    basic: true,
    process: true,
    material: true,
  };
  processId:number=null;
  jobOrderDetail:any={}
  Material=[];
  ngOnInit(): void {
    this.ActivatedRoute.params.subscribe((params)=>{
      this.jobOrderId=params.jobOrderId;
      this.JobOrderService.GetJobOrderById(this.jobOrderId).subscribe((data:any)=>{
        this.jobOrderDetail=data;
        this.Material = data.jobOrderProcesses.map((process: {
          processName: any;
          processNum: any;
          processNumber: any; parts: any[]}, index: number) => {
          return process.parts.map(part => {
            return {
              ...part,
              processNum: process.processNum,// 添加工序序号属性
              processName: process.processName  // 添加工序序号属性
            };
          });
        }).reduce((acc: string | any[], val: any) => acc.concat(val), []);

      })
    })
  }
  getjobOrderProcessId(id:number){
    this.processId=id;
  }
  cancel(){
    this.Router.navigate(['/pages/product/product-job'])
  }
}
